package com.heba.greenmulu.diary;

import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;

import com.heba.config.CommonConfig;
import com.heba.greenmulu.BaseActivity;
import com.heba.greenmulu.R;

import java.io.File;

/**
 * 预览视频
 * Created by jason on 2020/3/18.
 */
public class ItemDiaryVideoPreviewActivity extends BaseActivity {

    private VideoView videoView;

    private int type = 0;   //0表示播放本地视频 1表示播放网络视频
    private String videoPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diary_video_preview);
        initTopbar();
        findViewById();
        initView();
    }

    @Override
    protected void findViewById() {
        videoView = findViewById(R.id.videoView);
    }

    @Override
    protected void initView() {
        txt_title.setText(getResources().getString(R.string.diary_video_preview));

        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            type = bundle.getInt(CommonConfig.TYPE, 0);
            videoPath = bundle.getString(CommonConfig.DIARY_VIDEO, "");
        }

        if (type == 1) {
            //播放网络视频
            videoView.setVideoPath(videoPath);
            videoView.requestFocus();
            videoView.start();
        } else {
            if (!videoPath.isEmpty()) {
                File videoFile = new File(videoPath);
                if (videoFile.exists()) {
                    //播放本地視頻
                    videoView.setVideoURI(Uri.fromFile(videoFile));
                    videoView.start();
                }
            }
        }
    }
}
